<template>
	<view style="width: 100%; height: 100%; align-items: center;justify-content: center; display: flex;">

		<view style="width: 80%; height: 80%;border-radius: 30rpx; display: flex;justify-content: center;">
			<view>
				<view>消费赠送积分设置</view>
				<uni-table>
					<uni-tr>
						<uni-th>
							加盟店
						</uni-th>
						<uni-th>
							每消费一元赠送积分
						</uni-th>
					</uni-tr>
					<uni-tr v-for="(item,index) in shoplist" :key="index">
						<uni-td>
							<view @click="setpoints(item)" style="width: 100%;">
								{{item.name}}
							</view>
						</uni-td>
						<uni-td align="right">
							<view @click="setpoints(item)" style="width: 100%;">
								{{item.pointsRate}}
							</view>
						</uni-td>
					</uni-tr>
				</uni-table>
				<view>
				</view>
			</view>
		</view>

		<uni-popup ref="setpointswindow">
			<view class="popwindowstyle">
				<view>设置消费赠送积分比例</view>
				<view>{{currentshop.name}}</view>
				<view style="margin-top: 50rpx;"><uni-easyinput v-model="newpointsrate" type="number"></uni-easyinput>
				</view>
				<view style="display: flex;justify-content: space-between; width: 100%;margin-top: 50rpx;">
					<button type="warn" size="mini" @click="setpointscancle">取消</button>
					<button type="primary" size="mini" @click="setpointssubmit">确定</button>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		postrequest
	} from '../../common/apis.js';

	export default {
		name: "pointsAboutSetup",
		data() {
			return {
				page: 1,
				pagesize: 20,
				shoplist: {},
				currentshop: {},
				newpointsrate: 1
			};
		},
		mounted() {
			this.geterpcorpshop()
		},
		methods: {
			setpointssubmit() {
				console.log(this.currentshop)
				let data = {
					username: uni.getStorageSync('username', 'username'),
					password: uni.getStorageSync('password', 'password'),
					id: this.currentshop.id,
					pointsRate: this.newpointsrate
				}
				let url = 'https://www.jsyufang.com/yiXun/api/set_erp_corp_shop_pointsrate/index.asp'
				let errmessage = '调用获取门店列表接口失败'
				postrequest(url, data, errmessage, true)
					.then((res) => {
						console.log(res)
						if (res.data.code == 0) {
							this.geterpcorpshop()
							this.$refs.setpointswindow.close()
						}
					})
			},
			setpointscancle() {
				this.$refs.setpointswindow.close()
			},
			setpoints(item) {
				this.currentshop = item
				this.newpointsrate = item.pointsRate
				this.$refs.setpointswindow.open('center')
			},
			geterpcorpshop() {
				console.log('geterpcorpshop')
				let data = {
					username: uni.getStorageSync('username', 'username'),
					password: uni.getStorageSync('password', 'password'),
					page: this.page,
					pagesize: this.pagesize,
				}
				let url = 'https://www.jsyufang.com/yiXun/api/get_erp_corp_shop/index.asp'
				let errmessage = '调用获取门店列表接口失败'
				postrequest(url, data, errmessage, true)
					.then((res) => {
						console.log(res)
						if (res.data.code == 0) {
							this.shoplist = res.data.data
						}
					})
			}
		}
	}
</script>

<style>
	.popwindowstyle {
		width: 500rpx;
		height: auto;
		max-height: 90vh;
		background-color: white;
		border-radius: 30rpx;
		padding: 30rpx;
		justify-content: center;
		overflow-y: auto;
	}
</style>